<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="puid" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puid', validatorRules.puid]" placeholder="请输入puid"></a-input>
        </a-form-item>
        <a-form-item label="采购方编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchasercode', validatorRules.purchasercode]" placeholder="请输入采购方编码"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'datasource', validatorRules.datasource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliercode', validatorRules.suppliercode]" placeholder="请输入供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliername', validatorRules.suppliername]" placeholder="请输入供应商名称"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclasscode', validatorRules.subclasscode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="操作类型(同步/抓取/校审)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'operationtype', validatorRules.operationtype]" placeholder="请输入操作类型(同步/抓取/校审)"></a-input>
        </a-form-item>
        <a-form-item label="操作人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'userid', validatorRules.userid]" placeholder="请输入操作人员"></a-input>
        </a-form-item>
        <a-form-item label="操作日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择操作日期" v-decorator="[ 'operationdate', validatorRules.operationdate]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="IP地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ip', validatorRules.ip]" placeholder="请输入IP地址"></a-input>
        </a-form-item>
        <a-form-item label="采集同步数据PUID(数据采集信息表/数据同步信息表PUID)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'linkpuid', validatorRules.linkpuid]" placeholder="请输入采集同步数据PUID(数据采集信息表/数据同步信息表PUID)"></a-input>
        </a-form-item>
        <a-form-item label="批注(错误信息)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'comment', validatorRules.comment]" placeholder="请输入批注(错误信息)"></a-input>
        </a-form-item>
        <a-form-item label="详细信息(JSON串)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['detailedinformation']" rows="4" placeholder="请输入详细信息(JSON串)"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "EipDataDetailedInfoModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        puid:{rules: [{ required: true, message: '请输入puid!' }]},
        purchasercode:{rules: [{ required: true, message: '请输入采购方编码!' }]},
        datasource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        suppliercode:{rules: [{ required: true, message: '请输入供应商编码!' }]},
        suppliername:{rules: [{ required: true, message: '请输入供应商名称!' }]},
        subclasscode:{},
        operationtype:{rules: [{ required: true, message: '请输入操作类型(同步/抓取/校审)!' }]},
        userid:{rules: [{ required: true, message: '请输入操作人员!' }]},
        operationdate:{rules: [{ required: true, message: '请输入操作日期!' }]},
        ip:{rules: [{ required: true, message: '请输入IP地址!' }]},
        linkpuid:{},
        comment:{},
        detailedinformation:{},
        },
        url: {
          add: "/pg/eipDataDetailedInfo/add",
          edit: "/pg/eipDataDetailedInfo/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid','purchasercode','datasource','suppliercode','suppliername','subclasscode','operationtype','userid','operationdate','ip','linkpuid','comment','detailedinformation'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','purchasercode','datasource','suppliercode','suppliername','subclasscode','operationtype','userid','operationdate','ip','linkpuid','comment','detailedinformation'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>